<template>
	<view class="content">
		<view class="nav-body" v-if="routeList.length">
			<view class="sub" v-for="(item, index) in routeList" :key="index" @click="selectRoute(item)">
				<view :class="[cssTag(item.status || 0)]">{{ textTag(item.status || 0) }}</view>
				<view class="sub-row">
					<view class="line">
						<u-tag :text="item.lineName"></u-tag>
						<scroll-view scroll-x scroll-left="0">
							<view class="step" :style="'width:' + stepWidth">
								<u-steps current="1" dot>
									<u-steps-item :title="litem.name" v-for="(litem, lindex) in item.stations" :key="lindex">
										<view class="slot-icon slot-right" slot="icon"></view>
									</u-steps-item>
								</u-steps>
							</view>
						</scroll-view>
						<view class="footer">
							<view class="cell">
								<text class="cell-title">司机：</text>
								<text class="cell-content">{{ item.driverName }}</text>
								<text class="cell-content">{{ item.driverPhone }}</text>
							</view>
							<view class="cell">
								<view class="cell-row-left">
									<text class="cell-title">编号：</text>
									<text class="cell-content">{{ item.vehicleCode }}</text>
								</view>
								<view class="cell-row-right">
									<text class="cell-title">车牌：</text>
									<text class="cell-content">{{ item.plateNumber }}</text>
								</view>
							</view>
							<view class="cell">
								<text class="cell-title">发车时间：</text>
								<text class="cell-content-time">{{ item.taskTime }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<empty class="nav-body" v-else text="今日无排班数据"></empty>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';
import globaljs from '@/api/global.js';
import common from '@/utils/common.js';
import date from '@/utils/date.js';
import empty from '@/components/empty.vue';
export default {
	data() {
		return {
			stepWidth: '100%',
			routeList: []
		};
	},
	components: { empty },
	computed: { ...mapGetters(['token']) },
	onLoad() {
		// #ifdef MP
		//未登录转登录页面，已登录转主页面
		if (!this.$store.dispatch('checkIndentity')) return;
		// #endif
		this.todayOrders();
	},
	methods: {
		selectRoute(item) {
			let pages = getCurrentPages();
			let prevPage = pages[pages.length - 2];
			prevPage.$vm.onTask = item;
			uni.navigateBack({
				delta: 1
			});
		},
		async todayOrders() {
			let res = await globaljs.getHistoryOrders(date.formatDate(new Date(), 0), this.token);
			if (common.httpIsWrong(res)) return;
			this.routeList = res.json.data.data;
		},
		boxTag: (status) => {
			switch (status) {
				case 4:
				case 9:
					return 'sub color-sub';
				case 2:
				case 3:
					return 'sub color-sub2';
				case 0:
				case 1:
					return 'sub color-sub3';
			}
		},
		cssTag: (status) => {
			switch (status) {
				case 4:
				case 9:
					return 'tag-vertical color-tip';
				case 2:
				case 3:
					return 'tag-vertical color-tip2';
				case 0:
				case 1:
					return 'tag-vertical color-tip3';
			}
		},
		textTag: (status) => {
			switch (status) {
				case 4:
				case 9:
					return '已完成';
				case 2:
				case 3:
					return '进行中';
				case 0:
				case 1:
					return '未开始';
			}
		}
	}
};
</script>

<style lang="scss">
.content {
	height: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	.nav-body {
		width: 100%;
		height: 100%;
		padding-bottom: 100rpx;
		background-color: white;
		.color-sub {
			background-color: #c1d8d9;
		}
		.color-sub2 {
			background-color: #fff3e2;
		}
		.color-sub3 {
			background-color: #eaeaea;
		}
		.sub {
			height: auto;
			display: flex;
			flex-direction: column;
			margin: 30rpx 20rpx;
			border-radius: 10rpx;
			background-color: #f7f7f7;
			box-shadow: 0px 1px 5px #888888;
			position: relative;
			.tag-vertical {
				position: absolute;
				top: 0;
				right: 0;
				padding: 8rpx 0;
				width: 28px;
				color: #fff;
				text-align: center;
				border-radius: 0 10rpx 0 0;
			}
			.tag-vertical::after {
				position: absolute;
				content: '';
				right: 0;
				top: 100%;
				border-style: solid;
				border-width: 0 14px 14px 14.5px;
			}
			.tag-vertical.color-tip::after {
				border-color: #00d9a9 #00d9a9 transparent #00d9a9;
			}
			.tag-vertical.color-tip {
				background: #00d9a9;
			}
			.tag-vertical.color-tip2::after {
				border-color: #ff5500 #ff5500 transparent #ff5500;
			}
			.tag-vertical.color-tip2 {
				background: #ff5500;
			}
			.tag-vertical.color-tip3::after {
				border-color: #d1d1d1 #d1d1d1 transparent #d1d1d1;
			}
			.tag-vertical.color-tip3 {
				background: #d1d1d1;
			}
			.sub-row {
				display: flex;
				margin-right: 28px;
				border: solid 1rpx #3c9cff;
				border-top: none;
				background-color: #3c9cff;
				border-radius: 10rpx 0 0 10rpx;
				.line {
					width: 100%;
					position: relative;
					.footer {
						padding: 10rpx 20rpx;
						background-color: #e8f2fe;
						border-radius: 0 0 0 10rpx;
						.cell {
							padding: 10rpx 0;
							display: flex;
							.cell-title {
								letter-spacing: 10rpx;
								font-size: 28rpx;
							}
							.cell-content {
								letter-spacing: 10rpx;
								font-size: 28rpx;
								color: #1a90e4;
								margin: 0 20rpx;
							}
							.cell-content-time {
								letter-spacing: 5rpx;
								font-size: 28rpx;
								color: #1a90e4;
								margin: 0 20rpx;
							}
							.cell-content2 {
								font-size: 28rpx;
								color: #1a90e4;
								margin: 0 20rpx;
							}
							.cell-row-left {
								width: 40%;
							}
							.cell-row-right {
								flex: 1;
							}
							.cell-row {
								width: 50%;
							}
						}
					}
					.step {
						height: auto;
						background-color: white;
						display: flex;
						border-bottom: solid 1px #1a90e4;
						min-width: 100%;
						padding: 10rpx 0;
						.slot-icon {
							width: 20rpx;
							height: 20rpx;
							border-radius: 50%;
						}
						.slot-left {
							background-color: #969799;
						}
						.slot-right {
							background-color: #00ff7f;
						}
						.slot-mid {
							background-color: #ff0000;
						}
					}
				}
				.row {
					width: 50%;
				}
				.row-name {
					letter-spacing: 10rpx;
				}
				.row-cell {
					color: #1a90e4;
					margin: 0 20rpx;
				}
			}
		}
	}
}
::v-deep .u-text__value {
	writing-mode: vertical-lr;
	flex: auto;
}
</style>
